//---------------------------------------------------------------------------

#ifndef RIFFH
#define RIFFH

//#include <mmsystem.h> // Sound Playing Compatability

#include <stdio.h>
#include <iostream.h>

#include "cbuffer.h"
#include "twocc.h"
#include "convert.h"

#define quote "Programming today is a race between software engineers\n\
striving to build bigger and better idiot-proof programs,\n\
and the Universe trying to produce bigger and better idiots.\n\
\n\
So far, the Universe is winning."

typedef struct {
           unsigned short audioformat;
           unsigned short channels;
           unsigned int   samplerate;
           unsigned int   bitrate;
           unsigned short bytepersample;
           unsigned short bitpersample;
           } fmt_data;

           

class writeRIFF
  {
  private:
    FILE           *MyFile;
    int            datastart;
    int            datalenght;
    fmt_data       fmt_header;

  public:
                   writeRIFF( FILE *File );
    void           start_data_chunk();
    void           end_data_chunk();
    void           writesample(unsigned int sample, signed short data, signed short channel);
    void           fmt_chunk( fmt_data my_fmt_header );
    void           close();
  };



class readRIFF
  {
  private:

    FILE           *MyFile;
    char           filetype[4];
    char           subtype[4];
    unsigned int   datasize;
    unsigned int   filesize;
    unsigned int   readpos;
    unsigned int   datastart;
    bool           endian;
    char           chunkname[4];
    unsigned int   chunksize;
    fmt_data       fmt_header;

  public:

                   readRIFF ( FILE *File );
    unsigned int   samples();
    bool           findchunk(char chunk[4]);
    fmt_data       readfmt();
    string         getfiletype();
    string         audioformatname();
    unsigned short audioformat();
    unsigned short channels();
    unsigned int   samplerate();
    unsigned int   bitrate();
    unsigned short bytepersample();
    unsigned short bitpersample();
    signed short   readsample(unsigned int sample, unsigned short channel); // read 16 bit sample
    bool           gotosample(unsigned int); // seek
    unsigned int   gotodatastart();
    void           closeRIFFfile();
    void           GetRawAudio(signed short **RawAudio);
  };

//---------------------------------------------------------------------------
#endif
